home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Location.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  3.0 KB  |  73 lines  |  [TEXT/Moml]

  1. (* Location -- reporting errors in source texts.
  2.  * For use with mosmllex and mosmlyac.  Example in mosml/examples/lexyacc/.
  3.  * Based on src/compiler/location from the Caml Light 0.6 distribution.
  4.  *)
  5.  
  6. datatype Location =  (* Source file positions                            *)
  7.     Loc of int       (* Position of the first character                  *)
  8.          * int       (* Position of the character following the last one *)
  9.  
  10. val errLocation : string * BasicIO.instream * Lexing.lexbuf 
  11.                   -> Location -> unit
  12. val errMsg      : string * BasicIO.instream * Lexing.lexbuf 
  13.                   -> Location -> string -> 'a
  14. val errPrompt : string -> unit; 
  15. val nilLocation : Location
  16. val getCurrentLocation : unit -> Location
  17. val mkLoc : 'a -> Location * 'a
  18. val xLR   : Location * 'a -> Location
  19. val xL    : Location * 'a -> int
  20. val xR    : Location * 'a -> int
  21. val xxLR  : Location * 'a -> Location * 'b -> Location
  22. val xxRL  : Location * 'a -> Location * 'b -> Location
  23.  
  24. (* 
  25.    [errLocation (file, stream, lexbuf) loc] prints the part of the lexer 
  26.    input which is indicated by location loc.  
  27.    
  28.    If file <> "" then it is assumed to be the name of the file from
  29.    which the lexer reads, the stream is assumed to be an open input
  30.    stream associated with this file, and lexbuf is the lexer buffer
  31.    used to read from the stream.  Under MS DOS (and presumably
  32.    Windows, OS/2, and MacOS), the stream must have been opened in
  33.    binary mode (with Nonstdio.open_in_bin), or else the positioning in
  34.    the file will be wrong (due to the translation of CRLF into
  35.    newline).
  36.  
  37.    If file = "" then the lexer is assumed to read from some source
  38.    other than a stream, and the lexbuf (rather than the instream) is
  39.    used to obtain the location indicated, if possible.  In this case
  40.    the stream is immaterial; it will not be used.
  41.  
  42.    [errMsg (file, stream, lexbuf) loc msg] calls errLocation to print
  43.    the indicated part of the lexer input, then prints the error
  44.    message msg and raises exception Fail.
  45.  
  46.    [errPrompt msg] prints "! ", the string msg, and a newline on
  47.    standard output.  
  48.  
  49.    [nilLocation] is the undefined location.
  50.  
  51.    [getCurrentLocation ()] can be called within the semantic action
  52.    part of a grammar rule (only) and returns the location of the
  53.    string matching the left-hand side of the rule.
  54.  
  55.    [mkLoc a] can be called within the semantic action part of a
  56.    grammar rule (only), and returns a pair (loc, a) of the current
  57.    location and the value a.  This is typically used to decorate
  58.    abstract syntax tree nodes with location information, for use in
  59.    subsequent error reports.
  60.  
  61.    [xLR loc_a] returns the location of the decorated value loc_a.
  62.  
  63.    [xL loc_a] returns the left end position of loc_a.
  64.  
  65.    [xR loc_a] returns the right end position of loc_a.
  66.  
  67.    [xxLR loc_a loc_b] returns the location extending from the left end
  68.    of loc_a to the right end of loc_b.
  69.  
  70.    [xxRL loc_a loc_b] returns the location extending from the right end
  71.    of loc_a to the left end of loc_b.
  72. *)
  73.